// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class PATHWAY_CCM_I21 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("132 PTH",132)]
  	    [HL7Field(HL7Version.v27, 132, HL7Repeat.False, HL7Required.True,"PTH")]
	    public PTH PTH {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("133 VAR",133)]
  	    [HL7Field(HL7Version.v27, 133, HL7Repeat.True, HL7Required.False,"VAR")]
	    public VAR[] VAR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("134 ROLE_PATHWAY",134)]
  	    [HL7Field(HL7Version.v27, 134, HL7Repeat.True, HL7Required.False,"ROLE_PATHWAY_CCM_I21")]
	    public ROLE_PATHWAY_CCM_I21[] ROLE_PATHWAY {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("144 OBX",144)]
  	    [HL7Field(HL7Version.v27, 144, HL7Repeat.True, HL7Required.False,"OBX")]
	    public OBX[] OBX {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			PTH = PopSegmentParseAndCheckRequired<PTH>(availableData, options, "PTH");
			VAR = PopSegmentParseAndCheckRequiredArray<VAR>(availableData, options, "VAR");
			ROLE_PATHWAY = ProcessGroupArray<ROLE_PATHWAY_CCM_I21>(availableData, options, "ROLE_PATHWAY");
			OBX = PopSegmentParseAndCheckRequiredArray<OBX>(availableData, options, "OBX");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isPTH = availableData.StartsWith("PTH", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PTH", options.Version) || isPTH) {
				return isPTH;
			}
			bool isVAR = availableData.StartsWith("VAR", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("VAR", options.Version) || isVAR) {
				return isVAR;
			}
			ROLE_PATHWAY_CCM_I21 testROLE_PATHWAY_CCM_I21 = new ROLE_PATHWAY_CCM_I21();
			bool grpCCROLE_PATHWAY_CCM_I21 = (testROLE_PATHWAY_CCM_I21.CanConsume(availableData, options));
			if (IsRequired("ROLE_PATHWAY", options.Version) || grpCCROLE_PATHWAY_CCM_I21) {
				return grpCCROLE_PATHWAY_CCM_I21;
			}
			bool isOBX = availableData.StartsWith("OBX", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("OBX", options.Version) || isOBX) {
				return isOBX;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "PATHWAY";
			}
        }

        static PATHWAY_CCM_I21() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(PATHWAY_CCM_I21));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (PTH != null) {
			string segmentValue = PTH.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (VAR != null && VAR.Length > 0) {
			for (int i = 0; i < VAR.Length; i++) {
				string segmentValue = VAR[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (ROLE_PATHWAY != null && ROLE_PATHWAY.Length > 0) {
			for (int i = 0; i < ROLE_PATHWAY.Length; i++) {
				string segmentValue = ROLE_PATHWAY[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (OBX != null && OBX.Length > 0) {
			for (int i = 0; i < OBX.Length; i++) {
				string segmentValue = OBX[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

